package com.hb.gp.util.command;

import java.util.ArrayList;
import java.util.List;

import com.hb.gp.util.MsgGenUtil;
import com.hb.gp.util.SetParam;
import com.hb.gp.util.tools.DES;

public class APDU_CreateSessionKey {
	
	public List<String> createKeyScp01(String sessionId,List<String> keyset,String result) {
		String str = result.substring(32, 40)+ SetParam.GP_INIT_RANDOM.substring(0, 8)+ result.substring(24, 32)+ SetParam.GP_INIT_RANDOM.substring(8);
		String enc = DES.encryptTDES_ECB(MsgGenUtil.BCD2Bytes(keyset.get(0)), MsgGenUtil.BCD2Bytes(str));
		String mac = DES.encryptTDES_ECB(MsgGenUtil.BCD2Bytes(keyset.get(1)), MsgGenUtil.BCD2Bytes(str));
		List<String> list = new ArrayList<String>();
		list.add(enc);
		list.add(mac);
		list.add(keyset.get(2));
		//ShareParam.GP_SESSION_KEY.put(sessionId, list);
		return list;
	}
	
	public static List<String>  createKeyScp02(String sessionId,List<String> keyset,String initresponse) {
		String pbCardChallenge = initresponse.substring(24, 40);
		String src = "0182" + pbCardChallenge.substring(0, 4) + "000000000000000000000000";
		String pbCardKeyEncSk = DES.encryptTDS_CBC(MsgGenUtil.BCD2Bytes(keyset.get(0)), MsgGenUtil.BCD2Bytes(src));
		src = "0101" + pbCardChallenge.substring(0, 4) + "000000000000000000000000";
		String pbCardKeyMacSk = DES.encryptTDS_CBC(MsgGenUtil.BCD2Bytes(keyset.get(1)), MsgGenUtil.BCD2Bytes(src));
		src = "0181" + pbCardChallenge.substring(0, 4) + "000000000000000000000000";
		String pbCardKeyDekSk = DES.encryptTDS_CBC(MsgGenUtil.BCD2Bytes(keyset.get(2)), MsgGenUtil.BCD2Bytes(src));
		List<String> sessionKey = new ArrayList<String>();
		sessionKey.add(pbCardKeyEncSk);
		sessionKey.add(pbCardKeyMacSk);
		sessionKey.add(pbCardKeyDekSk);
		//ShareParam.GP_SESSION_KEY.put(sessionId, sessionKey);
		return sessionKey;
	}
	
	public List<String> createKeyScp10(String iccid,List<String> keyset,String initresponse) {
		List<String> sessionKey = new ArrayList<String>();
		return sessionKey;
	}
	
	public List<String> createKeyScp80(String iccid,List<String> keyset,String initresponse) {
		List<String> sessionKey = new ArrayList<String>();
		return sessionKey;
	}
}
